home *** CD-ROM | disk | FTP | other *** search
/ Acorn RISC PD-CD 1 / Acorn RISC PD-CD 1.iso / languages / grs / pd_release / g / m2 < prev    next >
Encoding:
Text File  |  1991-04-05  |  2.4 KB  |  93 lines

  1. integer function abs( integer i )
  2. {
  3. if i<0 then
  4.    return(-i);
  5. else
  6.    return(i);
  7. endif;
  8. };
  9.  
  10.  
  11. assume string side; integer x,y,skill; (null) expression tactic in
  12. {
  13.    let (null) expression movefunc :=
  14.      {
  15.         null function move()
  16.         {
  17.            integer shot;
  18.            integer epos;
  19.            integer ex,ey;
  20.  
  21.            foreach i in tank.get_instances() do
  22.            {
  23.               shot := false;
  24.               epos := i.get_pos(side);
  25.               ey := epos/256;
  26.               ex := epos - (ey*256);
  27.               if epos<>-1 and abs(y-ey)<4 and abs(x-ex)<4 and rnd(3)<>1 then
  28.                  shot := true;
  29.                  foreach s in [".","|",".","|",".","|",
  30.                                ".","|",".","|",".","|",
  31.                                ".","|",".","|",".","|",
  32.                                ".","|",".","|",".","|",
  33.                                ".","|",".","|",".","|",
  34.                                ".","|",".","|",".","|"] do
  35.                  {
  36.                     tab(x,y);
  37.                     write(s);
  38.                  };
  39.                  if rnd(100)<skill then
  40.                     i.blowup();
  41.                     sys_delete_object(i,false);
  42.                  endif;
  43.               endif;
  44.               if not shot then
  45.                  run(tactic);
  46.                  if rnd(10)=1 then
  47.                     integer nt;
  48.                     nt := rnd(10);
  49.                     if nt=1 or nt=2 then
  50.                        i.set_tactic(retreat);
  51.                     else
  52.                        if nt=3 or nt=4 or nt=5 then
  53.                           i.set_tactic(advance);
  54.                        else
  55.                           if nt=6 then
  56.                              i.set_tactic(panic);
  57.                           else
  58.                              if nt>6 then
  59.                                 i.set_tactic(default);
  60.                              endif;
  61.                           endif;
  62.                        endif;
  63.                     endif;
  64.                  endif;
  65.               endif;
  66.            };
  67.         };
  68.      };
  69. };
  70.  
  71.  
  72. tank.add_method( movefunc );
  73.  
  74. #tank gt1;
  75. #tank at1;
  76. #tank gt2;
  77. #tank at2;
  78. #tank gt3;
  79. #tank gt4;
  80. #tank at3;
  81. #tank gt5;
  82.  
  83.  
  84. gt1.set("German",10,3,30);
  85. gt2.set("German",10,6,30);
  86. gt3.set("German",10,9,30);
  87. gt4.set("German",10,12,30);
  88. gt5.set("German",10,15,30);
  89.  
  90. at1.set("American",15,5,60);
  91. at2.set("American",15,15,60);
  92. at3.set("American",25,10,90);
  93.